package com.qiusuo0226.core.pojo.query;

import com.qiusuo0226.common.util.BeanContext;
import com.qiusuo0226.common.util.ConvertTool;
import com.qiusuo0226.security.config.SecurityProperty;
import com.qiusuo0226.security.util.AesTool;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import javax.validation.constraints.NotBlank;

/**
 * 用户信息 新增 接口入参绑定对象
 * @author qiusuo
 * @date 2023/6/24 21:47
 */
@Data
public class UserInfoAddBean {

    private static final SecurityProperty property = BeanContext.getBean(SecurityProperty.class);
    /**
     * 账号
     */
    @NotBlank(message = "账号不能为空")
    private String account;

    /**
     * 登录密码
     */
    @NotBlank(message = "密码不能为空")
    private String pwd;

    /**
     * todo 属性解密
     */
    public void decrypt() throws Exception {

        if (StringUtils.isNotBlank(account)) {
            account = AesTool.decryptECB(ConvertTool.hexToBytes(account), ConvertTool.hexToBytes(property.getAesKey()));
        }

        if (StringUtils.isNotBlank(pwd)) {
            pwd = AesTool.decryptECB(ConvertTool.hexToBytes(pwd), ConvertTool.hexToBytes(property.getAesKey()));
        }
    }

}
